package com.qiang.work.test09;

import java.io.*;
import java.util.*;

public class Demo02 {
    public static void main(String[] args) throws IOException {

        StringBuilder sb = new StringBuilder();
        Scanner sc = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            System.out.println("请输入第" + (5 - i) + "个字符串");

            String s = sc.nextLine();
            list.add(s);
        }
        TreeMap<Integer, String> array = new TreeMap<>();
        for (String s : list) {
            array.put(s.length(), s);
        }

        //=================================================

        Set<Integer> keyset = array.keySet();
        for (Integer key : keyset) {
            list2.add(array.get(key));
        }
        for (int i = list2.size() - 1; i >= 0; i--) {
            //System.out.println(list.get(i));
            if (i > 0) {
                sb.append(list2.get(i) + ",");
            } else if (i == 0) {
                sb.append(list.get(i));
            }
        }
        //System.out.println(sb);
        //创建字符输出流
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day18\\info.txt"));

        //创建读取流
        String s = sb.toString();
        byte[] bytes = s.getBytes();
        bos.write(bytes);
        bos.close();
    }
}
